home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0100_Change specific color cell in TStringGri.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  1.3 KB  |  48 lines

  1. {
  2. >
  3. >I am trying to change the color of specific cell in TStringGrid.
  4. >Whenever I change the color of TStringGrid.Color, then the whole thing
  5. >(TStringGrid) is changed to the given color.
  6. >
  7. >If there is no way for doing this, are there any ways to change the
  8. >font of the text only for the specific cell ?
  9. >
  10. }
  11. This is off the top of my head:
  12.  
  13. 1.  You must set the DrawAutomatic property to False.
  14. 2.  You must create a method for the OnDrawCell event.
  15.  
  16. The OnDrawCell event would look something like:
  17.  
  18.   var
  19.     Text: array[0..255] of Char;
  20.   begin
  21.   StrPCopy (Text, StringGrid1.Cells[Row, Col]);
  22.   if Col = 2 then
  23.     StringGrid1.Canvas.Brush.Color := clYellow
  24.   else
  25.     StringGrid1.Canvas.Brush.Color := clWhite;
  26.   ExTextOut (..., Rect.Left + 2, Rect.Bottom + 2, ..., Text, StrLen (Text));
  27.   end;
  28.  
  29. This will draw the third column yellow and all others
  30. white.
  31.  
  32. Again the code and property names are off the top of my
  33. head.  If you have the VCL source, then take a look in
  34. the GRIDS.PAS file and you will see how the default
  35. OnDrawCell event uses the ExTextOut() function.  You
  36. could take the code from there and paste it into your
  37. source and then add the test for what color to draw the
  38. grid with.
  39.  
  40. Best regards,
  41. Michael Vincze
  42. mav@asd470.dseg.ti.com
  43.  
  44.  
  45.  
  46.  
  47.  
  48.